/**
 * Created by alan on 2017/5/5.
 * 菜单管理
 */
Ext.define('Admin.view.waterDispath.MenController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.menController',

    init: function() {},

    //steps下一步
    check: function() {
        var menGrid = this.lookupReference('menGrid');
        var store = menGrid.getStore();
        var name = this.lookupReference('name').getValue();

        store.getProxy().extraParams = { name: name, river: config.RIVER };
        store.reload();
    },
    add: function() {
        var that = this;
        var win = this.lookupReference('menuAddWindow');
        var menGrid = that.lookupReference('menGrid');
        var store = menGrid.getStore();
        if (!win) {
            win = Ext.create('Ext.window.Window', {
                title: '新增菜单',
                width: 500,
                //modal: true,
                layout: 'fit',
                closeAction: 'hide',
                reference: 'menuAddWindow',
                buttons: [{
                        text: '保存',
                        handler: function() {
                            var modal = this.up('window');
                            var form = that.lookupReference('menuAddForm').getForm();
                            if (form.isValid()) {
                                var values = form.getValues();
                                values.river = config.RIVER;
                                Ext.Ajax.request({
                                    url: config.URL + 'szy/sys/menu/save',
                                    method: "post",
                                    success: function(response, opts) {
                                        Ext.MessageBox.hide();
                                        var result = Ext.JSON.decode(response.responseText);
                                        if (result.code === 1) {
                                            Ext.Msg.alert('系统提示', "添加成功");
                                            store.reload();
                                            form.reset();
                                            modal.hide();
                                        } else {
                                            Ext.Msg.alert("系统提示", '添加失败“' + result.msg + '”');
                                        }
                                    },
                                    failure: function() {
                                        Ext.Msg.alert('系统提示', '系统出错！');
                                    },
                                    params: values
                                });
                            }
                        }
                    },
                    {
                        text: '取消',
                        handler: function() {
                            var modal = this.up('window');
                            that.lookupReference('menuAddForm').getForm().reset();
                            modal.hide()
                        }
                    }
                ],
                items: {
                    xtype: 'menuAdd',
                    border: false,
                    reference: 'menuAddForm'
                }
            });
            this.getView().add(win)
        }

        win.show();
    }


})